﻿Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data

Namespace HensonOnline
    Public Class Family


        Private _FamilyId As Integer
        Private _PFamilyId As Integer
        Private _FamilyName As String
        Private _Mother As String
        Private _Father As String
        Private _Address As String
        Private _City As String
        Private _State As String
        Private _Zip As String
        Private _Phone1 As String
        Private _Phone2 As String
        Private _MemberCount As Integer

        Public Property FamilyId() As Integer
            Get
                Return _FamilyId
            End Get
            Set(ByVal value As Integer)
                _FamilyId = value
            End Set
        End Property
        Public Property PFamilyId() As Integer
            Get
                Return _PFamilyId
            End Get
            Set(ByVal value As Integer)
                _PFamilyId = value
            End Set
        End Property
        Public Property FamilyName() As String
            Get
                Return _FamilyName
            End Get
            Set(ByVal value As String)
                _FamilyName = value
            End Set
        End Property
        Public Property Mother() As String
            Get
                Return _Mother
            End Get
            Set(ByVal value As String)
                _Mother = value
            End Set
        End Property
        Public Property Father() As String
            Get
                Return _Father
            End Get
            Set(ByVal value As String)
                _Father = value
            End Set
        End Property
        Public Property Address() As String
            Get
                Return _Address
            End Get
            Set(ByVal value As String)
                _Address = value
            End Set
        End Property
        Public Property City() As String
            Get
                Return _City
            End Get
            Set(ByVal value As String)
                _City = value
            End Set
        End Property
        Public Property State() As String
            Get
                Return _State
            End Get
            Set(ByVal value As String)
                _State = value
            End Set
        End Property
        Public Property Zip() As String
            Get
                Return _Zip
            End Get
            Set(ByVal value As String)
                _Zip = value
            End Set
        End Property
        Public Property Phone1() As String
            Get
                Return _Phone1
            End Get
            Set(ByVal value As String)
                _Phone1 = value
            End Set
        End Property
        Public Property Phone2() As String
            Get
                Return _Phone2
            End Get
            Set(ByVal value As String)
                _Phone2 = value
            End Set
        End Property
        Public Property MemberCount() As Integer
            Get
                Return _MemberCount
            End Get
            Set(ByVal value As Integer)
                _MemberCount = value
            End Set
        End Property

        Public Sub New()
            _FamilyId = 0
            _PFamilyId = 0
            _FamilyName = ""
            _Mother = ""
            _Father = ""
            _Address = ""
            _City = ""
            _State = ""
            _Zip = ""
            _Phone1 = ""
            _Phone2 = ""
            _MemberCount = 0
        End Sub

        Public Sub New(ByVal familyId As Integer)
            GetFamily(familyId)
        End Sub

        Public Function Create() As Integer
            Dim newFamilyId As Integer
            Dim sql As String = "[dbo].[sp_createFamily]"
            Dim comm As New SqlCommand(sql, conn)
            comm.CommandType = CommandType.StoredProcedure
            comm.Parameters.AddWithValue("@FamilyId", _FamilyId)
            comm.Parameters.AddWithValue("@PFamilyId", _PFamilyId)
            comm.Parameters.AddWithValue("@FamilyName", _FamilyName)
            comm.Parameters.AddWithValue("@Mother", _Mother)
            comm.Parameters.AddWithValue("@Father", _Father)
            comm.Parameters.AddWithValue("@Address", _Address)
            comm.Parameters.AddWithValue("@City", _City)
            comm.Parameters.AddWithValue("@State", _State)
            comm.Parameters.AddWithValue("@Zip", _Zip)
            comm.Parameters.AddWithValue("@Phone1", _Phone1)
            comm.Parameters.AddWithValue("@Phone2", _Phone2)
            comm.Parameters.AddWithValue("@MemberCount", _MemberCount)

            newFamilyId = comm.ExecuteScalar()

            Return newFamilyId
        End Function

        Public Function Create(ByVal familyId As Integer, ByVal pFamilyId As Integer, ByVal familyName As String, ByVal mother As String, ByVal father As String, ByVal address As String, ByVal city As String, ByVal state As String, ByVal zip As String, ByVal phone1 As String, ByVal phone2 As String, ByVal memberCount As Integer) As Integer
            Dim newFamilyId As Integer
            Dim sql As String = "[dbo].[sp_createFamily]"
            Dim comm As New SqlCommand(sql, conn)
            comm.CommandType = CommandType.StoredProcedure
            comm.Parameters.AddWithValue("@FamilyId", familyId)
            comm.Parameters.AddWithValue("@PFamilyId", pFamilyId)
            comm.Parameters.AddWithValue("@FamilyName", familyName)
            comm.Parameters.AddWithValue("@Mother", mother)
            comm.Parameters.AddWithValue("@Father", father)
            comm.Parameters.AddWithValue("@Address", address)
            comm.Parameters.AddWithValue("@City", city)
            comm.Parameters.AddWithValue("@State", state)
            comm.Parameters.AddWithValue("@Zip", zip)
            comm.Parameters.AddWithValue("@Phone1", phone1)
            comm.Parameters.AddWithValue("@Phone2", phone2)
            comm.Parameters.AddWithValue("@MemberCount", memberCount)

            newFamilyId = comm.ExecuteScalar()

            Return newFamilyId
        End Function

        Public Function GetFamilies() As DataTable
            Dim sql As String = "SELECT * FROM Families"
            Dim parameters As List(Of SqlParameter) = New List(Of SqlParameter)
            parameters.Add(New System.Data.SqlClient.SqlParameter("@FamilyId", FamilyId))
            Dim dt As DataTable = SelectList(sql, CommandType.Text, parameters.ToArray, dtFamilies())


            Return dt
        End Function



    End Class
End Namespace
